<template>
  <div class="dalog_one">
    <el-dialog
      title="编辑用户"
      :visible="visibleEdit"
      width="45%"
      @close="btnClose"
    >
      <!-- <template #title /> -->
      <!-- <span>这是一段信息</span> -->
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="企业名称" prop="shortName" label-width="20%">
          <el-input v-model="ruleForm.shortName" />
        </el-form-item>
        <el-form-item label="所属公司" prop="company" label-width="20%">
          <el-input v-model="ruleForm.company" />
        </el-form-item>
        <el-form-item label="活动区域" label-width="20%" style="margin-top:10px;">
          <!--  @province="onChangeProv"
            @city="onChangeCity"
            @area="onChangeArea" -->
          <v-distpicker
            :province="ruleForm.province"
            :city="ruleForm.city"
            hide-area
            @province="onChangeProv"
            @city="onChangeCity"
          />
          <el-input
            v-model="ruleForm.city"
            type="hidden"
            style="display:none"
          />
          <el-input
            v-model="ruleForm.city"
            type="hidden"
            style="display:none"
          />
        </el-form-item>
        <el-form-item
          label="方向(企业标签)"
          prop="tags"
          label-width="20%"
          style="margin-top:10px;"
        >
          <el-input
            v-model="ruleForm.tags"
          />
        </el-form-item>
        <el-form-item
          label="备注"
          prop="remarks"
          label-width="20%"
        >
          <el-input
            v-model="ruleForm.remarks"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btnClose">取 消</el-button>
        <el-button type="primary" @click="btnEdit">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import VDistpicker from 'v-distpicker'
import { getCompanysDetail, getCompanysEdit } from '@/api/company'
export default {
  components: { VDistpicker },
  props: {
    visibleEdit: {
      default: false,
      type: Boolean
    }
  },
  data() {
    return {
      id: 0,
      detailList: {},
      ruleForm: {
        remarks: '',
        tags: '',
        shortName: '',
        province: '',
        city: '',
        company: ''
      },
      rules: {

      }
    }
  },

  methods: {
    onChangeProv(e) {
      // console.log('省', e)
      this.ruleForm.province = e.value
    },
    // 监听市
    onChangeCity(e) {
      this.ruleForm.city = e.value
    },
    async btnEdit() {
      await getCompanysEdit(this.id, this.ruleForm)
      this.$emit('changeData')
      this.$emit('update:visible-edit', false)
      this.$refs.ruleForm.resetFields()
    },
    // 封装获取编辑数据回填的方法
    async getCompanysDetail(id) {
      // 编辑也需要用到id
      this.id = id
      const res = await getCompanysDetail(id)
      this.ruleForm = res
      // 服务器返给我1和0，提交布尔值
      this.ruleForm.isFamous === 1 ? this.ruleForm.isFamous = true : this.ruleForm.isFamous = false
    },
    btnClose() {
      this.$emit('update:visible-edit', false)
      this.$refs.ruleForm.resetFields()
    }
  }
}
</script>
  <style lang="scss">
  #app .el-textarea__inner{
      height: 100px;
  }
  .dalog_one{
      .el-dialog{
      .el-dialog__header{
      background-color: skyblue;
  }
  }
  }

  </style>

